

class ArrayStack:
    """
    Stack implementation using a python list.
    """
    def __init__(self):
        """
        Create an empty stack.
        """
        self._data = []

    def __len__(self):
        return len(self._data)

    def __str__(self):
        return str(self._data)

    def is_empty(self):
        return len(self._data) == 0

    def push(self, value):
        """
        Add element to the top of the stack.
        """
        self._data.append(value)

    def pop(self):
        if self.is_empty():
            raise Exception("stack is empty.")
        return self._data.pop()

    def top(self):
        if self.is_empty():
            raise Exception("stack is empty.")
        return self._data[-1]

    def transfer(self, T):
        """
        将stack中所有元素移动到stack T中
        :param T:
        :return:
        """
        if not self.is_empty():
            while(len(self._data) > 0):
                T.push(self.pop())

    def remove_all(self):
        """
        递归的方法删除stack
        :return:
        """
        if not self.is_empty():
            self.pop()
            self.remove_all()


